<%--
    Document   : detailproday
    Created on : Nov 20, 2011, 1:35:52 PM
    Author     : Venus
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.util.*, java.text.NumberFormat, Beans.ThamSoHT,Models.ThamSoHT_Model, Models.MonAn_Model, Models.TienTe_Model, Models.NhomMA_Model, Models.KhuyenMai_Model"%>
<%
            int langid = (Integer) session.getAttribute("langid"); // ngôn ngữ hiện tại
            String dsts = " 'delete', 'saleprice', 'price', 'dayinweek', 'foodname', 'chkpromsg', 'checksubmitmsg', 'discount', 'detailpromotionday', 'notice', 'promotion', 'rightmsg', 'foodgroupsname' ";
            ThamSoHT[] mdsts = ThamSoHT_Model.DSThamSo(dsts, langid); // mảng chứa các tham số của trang này.

            String checksubmitmsg = mdsts[0].getTenTS();
            String chkpromsg = mdsts[1].getTenTS();
            String dayinweek = mdsts[2].getTenTS();
            String delete = mdsts[3].getTenTS();
            String detailpromotionday = mdsts[4].getTenTS();
            String discount = mdsts[5].getTenTS();
            String foodgroupsname = mdsts[6].getTenTS();
            String foodname = mdsts[7].getTenTS();
            String notice = mdsts[8].getTenTS();
            String price = mdsts[9].getTenTS();
            String promotion = mdsts[10].getTenTS();
            String rightmsg = mdsts[11].getTenTS();
            String saleprice = mdsts[12].getTenTS();
            String msgchkpro = notice + "/" + chkpromsg;
            String msgright = notice + "/" + rightmsg;
            String msgsubmit = notice + "/" + checksubmitmsg;

            Vector vDSNT = (Vector) request.getAttribute("DSNT");
            Vector vDSNMA = (Vector) request.getAttribute("DSNMA");
            String makm = (String) request.getAttribute("makm");
            Vector vDSKMTN = (Vector) request.getAttribute("DSKMTN");

            int MaNMA = NhomMA_Model.LayMaNMA();
            int numpage = 0;// khởi tạo số trang = 0
            int vsize = vDSKMTN.size();
            if (vsize % 8 == 0) // mỗi trang có 6 dòng
            {
                numpage = vsize / 8;
            } else {
                numpage = vsize / 8 + 1;
            }
            String xx = (String) request.getAttribute("item"); // trang hiện tại đang xem
            int item = Integer.parseInt(xx);
            NumberFormat nf = NumberFormat.getNumberInstance(Locale.FRENCH);
            int total = 0;
%>
<script type="text/javascript">
    function keypress(e){
        //Hàm dùng để ngăn người dùng nhập các ký tự khác ký tự số vào TextBox
        var keypressed = null;
        if (window.event)
        {
            keypressed = window.event.keyCode; //IE
        }
        else
        {
            keypressed = e.which; //NON-IE, Standard
        }
        if (keypressed < 48 || keypressed > 57 )
        { //CharCode của 0 là 48 (Theo bảng mã ASCII)
            //CharCode của 9 là 57 (Theo bảng mã ASCII)
            if (keypressed == 8 || keypressed == 127  || keypressed == 44 || keypressed == 46  )
            {//Phím Delete và Phím Back
                return;
            }
            return false;
        }
    }
</script>
<h1><img style="margin-right: 13px; opacity: 0.8; margin-top: 4px;" alt="" src="../images/promotion11.png"><%=promotion%></h1>
<div class="cb"></div>
<div class="bloc" style=" margin-top: 15px;">
    <div class="title">
        <%=detailpromotionday%>        
    </div>
    <div class="content">
        <form name="AddDetailProDay" action="">
            <div  style="float: left; width: 22%; margin-bottom: 15px;">
                <label><%=foodgroupsname%></label>
                <select name="nhomma" class="text" style=" margin-bottom: 15px; padding-top: 3px; height: 25px;" lang="1" onchange="ShowListFood(this.lang, this.value)">
                <%
                    for(int i=0; i<vDSNMA.size(); i++){
                        Beans.NhomMA nma = (Beans.NhomMA) vDSNMA.elementAt(i);%>
                        <option value="<%=nma.getMaNMA() %>"><%=nma.getTenNMA() %></option>
                <%  }
                %>
                </select>
                <div class="cb"></div>
                <div id="dsma">
                <%
                    Vector vDSMA = new Vector();
                    vDSMA = MonAn_Model.LayDSMATheoNMA(langid, MaNMA);
                    int numpage1 = 0;// khởi tạo số trang = 0
                    int vsize1 = vDSMA.size();                    
                    if (vsize1 % 10 == 0) // mỗi trang có 6 dòng
                    {
                        numpage1 = vsize1 / 10;
                    } else {
                        numpage1 = vsize1 / 10 + 1;
                    }
                    String xx1 = "1";
                    int item1 = Integer.parseInt(xx1);

                    for (int j = (item1 - 1) * 10; j < (item1 - 1) * 10 + 10 && j < vsize1; j++){                        
                        Beans.MonAn ma = (Beans.MonAn) vDSMA.elementAt(j);%>
                        <% total = total + 1; %>
                        <div style=" width: 30px; float: left;"><input type="checkbox" name="chkma" alt="<%=ma.getMaMA() %>"></div>
                        <div><%=ma.getTenMA() %></div><br />
                <%  }
                %>
                <input type="hidden" name="total" value="<%=total%>">
                <div class="pagination" style=" margin-right: 20px;">
                <%
                    int trang1 = 1;
                    if (item1 > 1) {
                        trang1 = item1 - 1;
                    }
                %>
                <%
                    if (vsize1 > 10) {%>
                        <a href="#" class="prev"  name="<%= trang1%>" lang="<%=MaNMA %>" onclick="ShowListFood( this.name, this.lang)">«</a>
                <%      for (int c = 1; c <= numpage1; c++) {
                            if (c != item1) {
                %>              <a href="#"  name="<%= c%>" lang="<%=MaNMA %>" onclick="ShowListFood( this.name, this.lang)" ><%= c%></a>
                <%          } else {%><a class="current"> <%= c%></a> <% }
                        }
                %>
                <%      if (item1 + 1 <= numpage1) {
                            trang1 = item1 + 1;
                        } else {
                            trang1 = item1;
                        }
                %>
                        <a href="#" class="next"  name="<%= trang1%>" lang="<%=MaNMA %>" onclick="ShowListFood( this.name, this.lang)">»</a>
                <%  }
                %>
            </div>
                </div>
            </div>
            <div style="float: left; width: 17%; margin-bottom: 15px;">
                <label><%=discount%></label>
                <input type="textbox" class="text" onkeypress="return keypress(event)" name="discount" maxlength="2" style=" width: 40px; margin-bottom: 15px;">  %
                <div class="cb"></div>
                <%
                    for(int k=0; k<vDSNT.size(); k++){
                        Beans.NgayThu nt = (Beans.NgayThu) vDSNT.elementAt(k);
                        if(nt.getMaNgay() == 0){%>
                        <div style=" width: 30px; float: left;"><input type="checkbox" onclick="CheckAllNT()"  name="radnt" alt="<%=nt.getMaNgay() %>"></div>
                            <div><%=nt.getTenNgay() %></div><br />
                <%      }
                        else{%>
                        <div style=" width: 30px; float: left;"><input type="checkbox"  name="chknt" alt="<%=nt.getMaNgay() %>"></div>
                            <div><%=nt.getTenNgay() %></div><br />
                <%      }
                  }
                %>
                <input type="button" alt="<%=makm %>" id="<%=msgsubmit%>" lang="<%=msgchkpro%>" name="<%=msgright%>" onclick="AddProDay(this.alt, this.id, this.lang, this.name)" class="button" value=">>">
            </div>
            <div id="detailproday" style="float: left; width: 60%; margin-bottom: 15px;">
                <table class="mytable" border="0" cellpadding="0" cellspacing="0">
    <thead>
        <tr>
            <th style=" width: 25%;">
                <a href="#" id="titledskv1" style="margin-top: 5px;" class="down" lang="<%=msgright%>" shape="<%=makm %>"   name="1" onclick="SortTenMAKM(this.className, this.name, this.lang, this.shape)">
                    <div style="float:left"><%=foodname %></div>
                    <div id="sortkv1" style=" margin-right: 25px;" class="down1"></div>
                </a>
            </th>
            <th style="width: 17%;">
                <a href="#" id="titledskv2" style="margin-top: 5px;" class="down" lang="<%=msgright%>" shape="<%=makm %>"  name="1" onclick="SortNgayKM(this.className, this.name, this.lang, this.shape)">
                    <div style="float:left"><%=dayinweek%></div>
                    <div id="sortkv2" style=" margin-right: 15px;" class="down1"></div>
                </a>
            </th>
            <th style="width: 18%;">
                <a href="#" id="titledskv3" style="margin-top: 5px;" class="down" lang="<%=msgright%>" shape="<%=makm %>"  name="1" onclick="SortGiaKM(this.className, this.name, this.lang, this.shape)">
                    <div style="float:left"><%=price%> (<%=TienTe_Model.LayKyHieuTT(langid)%>)</div>
                    <div id="sortkv3" style=" margin-right: 20px;" class="down1"></div>
                </a>
            </th>
            <th style="width: 14%;">
                <%=discount %>
            </th>
            <th style="width: 19%;">
                <%=saleprice%> (<%=TienTe_Model.LayKyHieuTT(langid)%>)
            </th>
            <th><center><%=delete%></center></th>
        </tr>
        <tr id="searchaddpro">
            <th><input type="textbox"  style=" width: 110px;" class="tenma text"  ></th>
            <th><input type="textbox"  style=" width: 70px;" class="ngaythu text"></th>
            <th><input type="textbox"  style=" width: 60px;" class="gia text"  onkeypress="return keypress(event)"></th>
            <th><input type="textbox"  style=" width: 35px;" class="giamgia text"  maxlength="2" onkeypress="return keypress(event)"> %</th>
            <th></th>
            <th><img style=" margin-top: 2px; margin-left: 3px; margin-bottom: -7px; cursor: pointer;" name="<%=makm %>"  alt="1" src="../images/search1.png" lang="<%=msgright%>" onclick="SearchAddPro(this.alt, this.lang, this.name)"></th>
        </tr>
    </thead>
    <tbody>
        <%
            for (int i = (item - 1) * 8; i < (item - 1) * 8 + 8 && i < vsize; i++){
                Beans.KMTheoNgay kmtn = (Beans.KMTheoNgay) vDSKMTN.elementAt(i);%>
                <tr>
                    <td><%=MonAn_Model.LayTenMA(kmtn.getMaMA(), langid) %></td>
                    <td><%=KhuyenMai_Model.LayTenNgay(kmtn.getMaNgay(), langid)  %></td>
                    <td style="padding-right: 5px;"><div style="width: 50px; text-align: right;"><%=nf.format(MonAn_Model.LayGia(kmtn.getMaMA())) %></div></td>
                    <td>
                        <div style=" float: left; width: 55px;"><input type="textbox" onkeypress="return keypress(event)" class="text" maxlength="2" style=" width: 35px;" value="<%=kmtn.getGiamGia() %>" alt="<%=kmtn.getMaKMTN() %>" name="<%=kmtn.getMaKM() %>" id="<%=msgright%>" onchange="UpdateGiamGia(this.alt, this.value, this.name, this.id)">  %</div>
                        <img style=" cursor: pointer; height: 18px; padding-right: 0; margin-left: 6px; margin-top: 2px;" alt="" src="../images/addmoney.png">
                    </td>
                    <td><div style="width: 70px; text-align: right;"><%=nf.format(MonAn_Model.LayRsGia(kmtn.getMaMA(), kmtn.getGiamGia())) %></div></td>
                    <td><center><a href="#" id="<%=kmtn.getMaKMTN() %>" lang="<%=kmtn.getMaKM() %>" name="<%=msgright%>" onclick="DeleteProDay(this.id, this.name, this.lang)"><img style=" height: 18px; width: 18px;" alt="" src="../images/del.png"></a></center></td>
                </tr>
        <%  }%>
    </tbody>
</table>
<div class="pagination">
    <%
        int trang = 1;
        if (item > 1) {
            trang = item - 1;
        }
    %>
    <%
        if (vsize > 8) {%>
        <a href="#" class="prev"  name="<%= trang%>" lang="<%=msgright%>" id="<%=makm %>" onclick="ViewDetailProDay(this.name, this.lang, this.id)">«</a>
    <%      for (int c = 1; c <= numpage; c++) {
                if (c != item) {
    %>              <a href="#"  name="<%= c%>" lang="<%=msgright%>" id="<%=makm %>" onclick="ViewDetailProDay(this.name, this.lang, this.id)" ><%= c%></a>
    <%          } else {%><a class="current"> <%= c%></a> <% }
            }
    %>
    <%      if (item + 1 <= numpage) {
                trang = item + 1;
            } else {
                trang = item;
            }
    %>
            <a href="#" class="next"  name="<%= trang%>" lang="<%=msgright%>" id="<%=makm %>" onclick="ViewDetailProDay(this.name, this.lang, this.id)">»</a>
    <%  }
    %>
</div>
            </div>

        </form>
    </div>
</div>